import { Shake } from "../../../Core/FrameEx/ActionEx";
import GChild from "../../../Core/GView/GChild";
import { LNumber } from "../../Common/Language";



const { ccclass, property, menu } = cc._decorator;

@ccclass @menu('JXRB/JXRBFlags')
export default class JXRBFlags extends GChild {
	@property(cc.Sprite) hpBar: cc.Sprite = null;
	@property(cc.Label) lb_hp: cc.Label = null;
	@property(cc.Node) flags: cc.Node = null;

	public setHp(nTotal: number, nCur: number) {
		let isActive = this.node.active;
		this.node.active = true;
		let fillRange = nCur / nTotal;
		this.lb_hp.string = `${LNumber(nCur)}/${LNumber(nTotal)}`;
		cc.tween(this.hpBar).to(1, { fillRange: fillRange }).call(() => {
			if (!isActive) this.node.active = false;
		}).start()
	}

	public flagsShake() {
		this.flags.stopAllActions();
		let quakeAction = new Shake(0.3, 10, 0);
		this.flags.runAction(quakeAction);
	}
}